<?php

namespace App\Listener;

use App\Event\ConsumeEvent;
use App\Model\UserCharmRichLog;
use App\Model\UserProfile;
use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;

/**
 * @Listener 
 */
class UserRichChangeListener implements ListenerInterface
{
    public function listen(): array
    {
        // 返回一个该监听器要监听的事件数组，可以同时监听多个事件
        return [
            ConsumeEvent::class,
        ];
    }

    /**
     * @param UserRegistered $event
     */
    public function process(object $event)
    {
        //不变动豪气值
        if (!$event->changeRich) return false;
        $richValue = $event->costCoin * 10;
        //更新魅力值
        $result = UserProfile::where('user_id', $event->userId)->limit(1)->increment('rich_value', $richValue);
        UserCharmRichLog::addRichRecord($event->userId, $richValue);
        log_info(__CLASS__ . "=={$event->userId}=={$event->costCoin}");
    }
}
